package org.summerframework.core.util;

import org.summerframework.core.base.result.DefaultResultCode;
import org.summerframework.core.exception.SelectNullException;

import java.util.Optional;

/**
 * @author 石超
 * @version v1.0.0
 */
public class OptionalUtils {
    public static <T> T get(T t) {
        return Optional.ofNullable(t).orElseThrow(SelectNullException::new);
    }

    public static <T> T get(T t, String message) {
        return Optional.ofNullable(t).orElseThrow(() -> new SelectNullException(DefaultResultCode.ERROR_SELECT_IS_NULL, message));
    }
}
